#include "stm32f10x.h"                  // Device header


void PWM_Init(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitstructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;
	GPIO_InitTypeDef GPIO_InitStructure; //这个要前放,不然会有警告
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

	GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF_PP ;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP ;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 ;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
	TIM_InternalClockConfig(TIM2);
	TIM_TimeBaseInitstructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseInitstructure.TIM_CounterMode =TIM_CounterMode_Up ;
	TIM_TimeBaseInitstructure.TIM_Period = 200-1;    //ARR
	TIM_TimeBaseInitstructure.TIM_Prescaler =7200-1;   //PSC
	TIM_TimeBaseInitstructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitstructure);
	 
	
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1 ;
	TIM_OCInitStructure.TIM_OCPolarity =TIM_OCPolarity_High ;
	TIM_OCInitStructure.TIM_OutputState =TIM_OutputState_Enable ;
	TIM_OCInitStructure.TIM_Pulse =0 ;    //CCR的值
	TIM_OC1Init(TIM2,&TIM_OCInitStructure);
	TIM_OC2Init(TIM2,&TIM_OCInitStructure);
	
	TIM_Cmd(TIM2,ENABLE);
     
}

void PWM_SETDUTY1(uint16_t duty_channe1)
{
	TIM_SetCompare1(TIM1,duty_channe1 );
	
}
void PWM_SETDUTY2(uint16_t duty_channe2)
{
	TIM_SetCompare1(TIM1,duty_channe2 );
	
}
